var http = require('http'),  
superagent = require('superagent'),  
cheerio = require('cheerio'),  
mongoose = require('mongoose'),  
mongourl = 'mongodb://127.0.0.1:27017',
pageNum = 100

require('superagent-proxy')(superagent);
var proxy = process.env.http_proxy || 'http://H21XTU8514I45CDD:EE3F8E452496F88F@proxy.abuyun.com:9020';
var city = require('./city');
// 8d558e118f32f66f06fe9e5290cf10f0高德key


mongoose.Promise = global.Promise; 
mongoose.connect(mongourl,{useMongoClient:true});  
var Schema = mongoose.Schema;  
//骨架模版  
var movieSchema = new Schema({  
    name: String,
})  
//模型  
var Movie = mongoose.model('Movie', movieSchema);  
//存储数据  
var pageUrls=['http://restapi.amap.com/v3/place/text?&keywords=%E5%8C%97%E4%BA%AC%E5%A4%A7%E5%AD%A6&city=beijing&&offset=20&page=1&key=8d558e118f32f66f06fe9e5290cf10f0&extensions=all']



pageUrls.forEach(function(pageUrl){
    superagent.get(pageUrl)  
    .end(function(err,page){  
        var text=JSON.parse(page.text)
        console.log(text.pois[0])
        var moive = new Movie({  
            name : page  
        })  
        //保存数据库  
        moive.save(function(err) {  
            if (err) {  
                console.log('保存失败')  
                return;  
            }              
        })  
    })  
})  